<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('口令红包列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>名称：</label>
                                <input type="text" name="title"/>
                            </li>
                            <li>
                                <label>口令：</label>
                                <input type="text" name="code"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="lucky:bag:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="lucky:bag:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="lucky:bag:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="lucky:bag:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('lucky:bag:edit')}]];
        var removeFlag = [[${@permission.hasPermi('lucky:bag:remove')}]];
        var prefix = ctx + "lucky/bag";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "口令红包",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'title',
                    title: '名称'
                },
                {
                    field: 'code',
                    title: '口令'
                },
                {
                    field: 'number',
                    title: '数量'
                },
                {
                    field: 'price',
                    title: '金额'
                },
                {
                    field: 'afterTime',
                    title: '过期时间'
                },
                {
                    field: 'remarks',
                    title: '备注'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="bagInfo(\'' + row.id + '\')"><i class="fa fa-hand-lizard-o"></i>领取详情</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        /*领取详情*/
        function bagInfo(id, width, height){
            var _url = prefix + "/bagInfo?bagId="+id;
            var _width = $.common.isEmpty(width) ? "800" : width;
            var _height = $.common.isEmpty(height) ? ($(window).height() - 50) : height;
            //如果是移动端，就使用自适应大小弹窗
            if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
                _width = 'auto';
                _height = 'auto';
            }
            layer.open({
                type: 2,
                area: [_width + 'px', _height + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: '领取详情',
                content: _url,
                btn: '关闭',
                // 弹层外区域关闭
                // shadeClose: true,
                success: function (layer) {
                    layer[0].childNodes[3].childNodes[0].attributes[0].value = 'layui-layer-btn1';
                },
                btn1: function (index) {
                    layer.close(index);
                }
            });
        }
    </script>
</body>
</html>